<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>03_props的简写方式</title>
</head>
<body>
     <!-- 准备好一个“容器” -->
	<div id="test1"></div>
    <div id="test2"></div>
    <div id="test3"></div>
	
	<!-- 引入react核心库 -->
	<script type="text/javascript" src="../js/react.development.js"></script>
	<!-- 引入react-dom，用于支持react操作DOM -->
	<script type="text/javascript" src="../js/react-dom.development.js"></script>
	<!-- 引入babel，用于将jsx转为js -->
	<script type="text/javascript" src="../js/babel.min.js"></script>
    <!-- 引入prop-types，用于对组件标签属性进行限制 -->
	<script type="text/javascript" src="../js/prop-types.js"></script>

    <script type="text/babel">
        class Person extends React.Component{

            constructor(props){
				//构造器是否接收props，是否传递给super，取决于：是否希望在构造器中通过this访问props
				// console.log(props);
				super(props)
				console.log('constructor',this.props);
			}
            // 渲染的函数 
            render() {
                const {name,sex,age}=this.props
                	//props是只读的
				//this.props.name = 'jack' //此行代码会报错，因为props是只读的
                return <ul>
                        <li>姓名:{name}</li>
                        <li>年龄:{age+1}</li>
                        <li>性别:{sex}</li>
                    </ul>
            }

            static propTypes={
                name:PropTypes.string.isRequired,
                sex:PropTypes.string,
                age:PropTypes.number
            }

            static defaultProps={
                sex:'男',
                age:18
            }
        }
        ReactDOM.render(<Person name="jerry" />,document.getElementById('test1'))
    </script>
    
</body>
</html>